import React, { Component , Fragment } from 'react'
import { Link } from 'react-router-dom'
import './subGoodsList.css'
import axios from 'axios';
import img1 from '../../assets/homeGoods/g-item2.jpg'
import Toast from './../toast'
export default class SubGoodsList extends Component{
    constructor(props){
        super(props);
        this.state = {}
    }
    addCart = () => {
        axios.post('http://localhost:3000/api/add_shop_cart',{
            params:{
                goods_id:this.props.id,
                goods_name:this.props.title,
                thumb_url:this.props.pic,
                price:this.props.now_price,
            }
        }).then(res=>{
            if(res.data.success_code){
                Toast.info(res.data.message,2000);
            }
        })
    }
    render(){
        let {pic,title,describe,discount,now_price,prev_price,format,id} = this.props;
        return (
            <Fragment>
                <Link to={`/details/${id}`} className='single-fruit'>
                    <div className='fruit-thumb'>
                        <img src={pic} alt=''/>
                    </div>
                    <div className='fruit-remsg'>
                        <div className='sub-fruit-title'>{title}</div>
                        <div className='sub-fruit-describe'>{describe}</div>
                        <div className='sub-fruit-discount'>{discount}</div>
                        <div className='sub-fruit-price'>
                            <span>￥{now_price}</span>
                            <span>{prev_price}</span>
                            <span>{format}</span>
                            <img onClick={()=>{this.addCart()}} src='https://img05.yiguoimg.com/d/web/180508/01311/150610/add.png' alt=''/>
                        </div>
                    </div>
                </Link>
            </Fragment>
        )
    }
}